<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登陆密码" prop="userPass">
        <el-input
          v-model="queryParams.userPass"
          placeholder="请输入登陆密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="照片" prop="thumb">
        <el-input
          v-model="queryParams.thumb"
          placeholder="请输入照片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份id" prop="provinceId">
        <el-input
          v-model="queryParams.provinceId"
          placeholder="请输入省份id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除 1-删除  0-未删除" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入是否删除 1-删除  0-未删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运动等级" prop="level">
        <el-input
          v-model="queryParams.level"
          placeholder="请输入运动等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位，1教练员，2干事，3队医，4复合团队" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职位，1教练员，2干事，3队医，4复合团队"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职称" prop="zhicheng">
        <el-input
          v-model="queryParams.zhicheng"
          placeholder="请输入职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身高，以米为单位，小数点后两位" prop="height">
        <el-input
          v-model="queryParams.height"
          placeholder="请输入身高，以米为单位，小数点后两位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体重，以公斤为单位，保留2位" prop="weight">
        <el-input
          v-model="queryParams.weight"
          placeholder="请输入体重，以公斤为单位，保留2位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="籍贯" prop="nativePlace">
        <el-input
          v-model="queryParams.nativePlace"
          placeholder="请输入籍贯"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证地址" prop="idcardAddress">
        <el-input
          v-model="queryParams.idcardAddress"
          placeholder="请输入身份证地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证正面" prop="idcardFront">
        <el-input
          v-model="queryParams.idcardFront"
          placeholder="请输入身份证正面"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证反面" prop="idcardReverse">
        <el-input
          v-model="queryParams.idcardReverse"
          placeholder="请输入身份证反面"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件有效时间" prop="idcardTime">
        <el-input
          v-model="queryParams.idcardTime"
          placeholder="请输入证件有效时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现居住地" prop="currentAddress">
        <el-input
          v-model="queryParams.currentAddress"
          placeholder="请输入现居住地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校" prop="school">
        <el-input
          v-model="queryParams.school"
          placeholder="请输入学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学位" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入学位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学位证书" prop="degreeCertificate">
        <el-input
          v-model="queryParams.degreeCertificate"
          placeholder="请输入学位证书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历证书" prop="educationCertificate">
        <el-input
          v-model="queryParams.educationCertificate"
          placeholder="请输入学历证书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否在编，1在编，2空编" prop="isPayroll">
        <el-input
          v-model="queryParams.isPayroll"
          placeholder="请输入是否在编，1在编，2空编"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:coach:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:coach:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:coach:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:coach:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="coachList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="登陆密码" align="center" prop="userPass" />
      <el-table-column label="照片" align="center" prop="thumb" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="省份id" align="center" prop="provinceId" />
      <el-table-column label="城市id" align="center" prop="cityId" />
      <el-table-column label="是否删除 1-删除  0-未删除" align="center" prop="isDelete" />
      <el-table-column label="生日" align="center" prop="birthday" />
      <el-table-column label="从事运动开始的时间" align="center" prop="shootTime" />
      <el-table-column label="性别  1-男  2-女" align="center" prop="sex" />
      <el-table-column label="运动等级" align="center" prop="level" />
      <el-table-column label="1- 中共党员 2-中共预备党员 3-共青团员 4-民革党员 5-民盟盟员 6-民建会员 7-民进会员 8-农工党党员 9-致公党党员 10-九三学社社员 11-台盟盟员 12-无党派人士 13-群众" align="center" prop="zz" />
      <el-table-column label="职位，1教练员，2干事，3队医，4复合团队" align="center" prop="position" />
      <el-table-column label="职称" align="center" prop="zhicheng" />
      <el-table-column label="身高，以米为单位，小数点后两位" align="center" prop="height" />
      <el-table-column label="体重，以公斤为单位，保留2位" align="center" prop="weight" />
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="户籍类型，1城市，2农村" align="center" prop="houseType" />
      <el-table-column label="身份证地址" align="center" prop="idcardAddress" />
      <el-table-column label="身份证号码" align="center" prop="idCard" />
      <el-table-column label="身份证正面" align="center" prop="idcardFront" />
      <el-table-column label="身份证反面" align="center" prop="idcardReverse" />
      <el-table-column label="证件有效时间" align="center" prop="idcardTime" />
      <el-table-column label="婚姻状态，1未婚，2已婚，3离婚，4丧偶" align="center" prop="maritalStatus" />
      <el-table-column label="现居住地" align="center" prop="currentAddress" />
      <el-table-column label="学校" align="center" prop="school" />
      <el-table-column label="学位" align="center" prop="degree" />
      <el-table-column label="学位证书" align="center" prop="degreeCertificate" />
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="学历证书" align="center" prop="educationCertificate" />
      <el-table-column label="是否在编，1在编，2空编" align="center" prop="isPayroll" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:coach:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:coach:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改教练员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="登陆密码" prop="userPass">
          <el-input v-model="form.userPass" placeholder="请输入登陆密码" />
        </el-form-item>
        <el-form-item label="照片" prop="thumb">
          <el-input v-model="form.thumb" placeholder="请输入照片" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="省份id" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省份id" />
        </el-form-item>
        <el-form-item label="是否删除 1-删除  0-未删除" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入是否删除 1-删除  0-未删除" />
        </el-form-item>
        <el-form-item label="运动等级" prop="level">
          <el-input v-model="form.level" placeholder="请输入运动等级" />
        </el-form-item>
        <el-form-item label="职位，1教练员，2干事，3队医，4复合团队" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位，1教练员，2干事，3队医，4复合团队" />
        </el-form-item>
        <el-form-item label="职称" prop="zhicheng">
          <el-input v-model="form.zhicheng" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="身高，以米为单位，小数点后两位" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高，以米为单位，小数点后两位" />
        </el-form-item>
        <el-form-item label="体重，以公斤为单位，保留2位" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重，以公斤为单位，保留2位" />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="身份证地址" prop="idcardAddress">
          <el-input v-model="form.idcardAddress" placeholder="请输入身份证地址" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="idcardFront">
          <el-input v-model="form.idcardFront" placeholder="请输入身份证正面" />
        </el-form-item>
        <el-form-item label="身份证反面" prop="idcardReverse">
          <el-input v-model="form.idcardReverse" placeholder="请输入身份证反面" />
        </el-form-item>
        <el-form-item label="证件有效时间" prop="idcardTime">
          <el-input v-model="form.idcardTime" placeholder="请输入证件有效时间" />
        </el-form-item>
        <el-form-item label="现居住地" prop="currentAddress">
          <el-input v-model="form.currentAddress" placeholder="请输入现居住地" />
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校" />
        </el-form-item>
        <el-form-item label="学位" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入学位" />
        </el-form-item>
        <el-form-item label="学位证书" prop="degreeCertificate">
          <el-input v-model="form.degreeCertificate" placeholder="请输入学位证书" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="学历证书" prop="educationCertificate">
          <el-input v-model="form.educationCertificate" placeholder="请输入学历证书" />
        </el-form-item>
        <el-form-item label="是否在编，1在编，2空编" prop="isPayroll">
          <el-input v-model="form.isPayroll" placeholder="请输入是否在编，1在编，2空编" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCoach, getCoach, delCoach, addCoach, updateCoach } from "@/api/system/coach";

export default {
  name: "Coach",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教练员表格数据
      coachList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userPass: null,
        thumb: null,
        phone: null,
        email: null,
        provinceId: null,
        cityId: null,
        isDelete: null,
        birthday: null,
        shootTime: null,
        sex: null,
        level: null,
        zz: null,
        position: null,
        zhicheng: null,
        height: null,
        weight: null,
        nativePlace: null,
        houseType: null,
        idcardAddress: null,
        idCard: null,
        idcardFront: null,
        idcardReverse: null,
        idcardTime: null,
        maritalStatus: null,
        currentAddress: null,
        school: null,
        degree: null,
        degreeCertificate: null,
        education: null,
        educationCertificate: null,
        isPayroll: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户名不能为空", trigger: "blur" }
        ],
        userPass: [
          { required: true, message: "登陆密码不能为空", trigger: "blur" }
        ],
        thumb: [
          { required: true, message: "照片不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        email: [
          { required: true, message: "邮箱不能为空", trigger: "blur" }
        ],
        provinceId: [
          { required: true, message: "省份id不能为空", trigger: "blur" }
        ],
        cityId: [
          { required: true, message: "城市id不能为空", trigger: "blur" }
        ],
        isDelete: [
          { required: true, message: "是否删除 1-删除  0-未删除不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "最后更新时间不能为空", trigger: "blur" }
        ],
        birthday: [
          { required: true, message: "生日不能为空", trigger: "blur" }
        ],
        shootTime: [
          { required: true, message: "从事运动开始的时间不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别  1-男  2-女不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教练员列表 */
    getList() {
      this.loading = true;
      listCoach(this.queryParams).then(response => {
        this.coachList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        userPass: null,
        thumb: null,
        phone: null,
        email: null,
        provinceId: null,
        cityId: null,
        isDelete: null,
        createTime: null,
        updateTime: null,
        birthday: null,
        shootTime: null,
        sex: null,
        level: null,
        zz: null,
        position: null,
        zhicheng: null,
        height: null,
        weight: null,
        nativePlace: null,
        houseType: null,
        idcardAddress: null,
        idCard: null,
        idcardFront: null,
        idcardReverse: null,
        idcardTime: null,
        maritalStatus: null,
        currentAddress: null,
        school: null,
        degree: null,
        degreeCertificate: null,
        education: null,
        educationCertificate: null,
        isPayroll: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加教练员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCoach(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教练员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCoach(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCoach(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除教练员编号为"' + ids + '"的数据项？').then(function() {
        return delCoach(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/coach/export', {
        ...this.queryParams
      }, `coach_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
